<template>
  <div id="excellentWorks">
    <div class="excellentWorksContent">
      <div class="excellentWorksContentHeader">
        <div class="excellentWorksContentHeaderTab">
          <ul>
            <li v-for="(item, index) in headerTabArray" :key="index" @click="headerTab(index, item.classifyId)">
              <p :class="{blue: headerTabIndex === index}">{{item.classifyName}}</p>
              <span v-show="headerTabIndex === index"></span>
            </li>
          </ul>
        </div>
        <div class="excellentWorksContentHeaderSearch">
          <label for="searchStylist">
            <img src="../../assets/img/ideaMarket/sear.png" alt="">
            <input id="searchStylist" type="text" placeholder="请输入作品名称" v-model="searchText" @keydown.enter="getSkillSelectGood(classifyId)">
          </label>
          <button @click="getSkillSelectGood(classifyId)" style="background:#15A29C;color:#fff">搜索</button>
        </div>
      </div>
      <!--  -->
      <div class="skillLiftPublicBookFlexRight">
        <ul>
        <li
          v-for="(item, index) in classifyList"
          :key="index"
          @click="jumpTo('/worksDetail?worksId=' + item.id)"
        >
          <img
            class="publicBookFruitImg"
            :src="$globalImageUrl + item.literatureImg"
            alt=""
          />
          <p class="ellipse">{{ item.literatureName }}</p>
          <div class="publicBookRemark">
            <img src="../../assets/img/common/browse.png" alt="" />
            <span>{{ item.browseNum }}</span>
            <img src="../../assets/img/common/comment.png" alt="" />
            <span>{{ item.commentNum }}</span>
            <img src="../../assets/img/common/praise.png" alt="" />
            <span>{{ item.praiseNum }}</span>
          </div>
        </li>
      </ul>
      </div>
      <div class="pageNumber" v-if="pageTotals != 0">
        <div @click="prevPage(classifyId)">上一页</div>
        <div @click="nowPage(item, classifyId)" :class="{pageActive: pageActiveIndex === item}" v-for="(item, index) in pageTotals" :key="index">{{item}}</div>
        <div @click="nextPage(classifyId)">下一页</div>
      </div>
    </div>
  </div>
</template>

<script>
import pageNumber from '../../components/pageNumber/index'
export default {
  name: 'excellentWorks',
  components: {
    pageNumber
  },
  data () {
    return {
      pageTotals: 1,
      pageActiveIndex: 1,
      searchText: '',
      headerTabIndex: 0,
      headerTabArray: [],
      classifyList: [],
      classifyId: 1
    }
  },
  created () {
    this.getSkillSelectClassify()
    this.getSkillSelectGood()
  },
  methods: {
    // 上一页
    prevPage () {
      if (this.pageActiveIndex > 1) {
        this.pageActiveIndex--
        this.getSkillSelectGood()
      }
    },
    // 下一页
    nextPage () {
      if (this.pageTotals > this.pageActiveIndex) {
        this.pageActiveIndex++
        this.getSkillSelectGood()
      }
    },
    // 选择页码
    nowPage (index) {
      this.pageActiveIndex = index
      this.getSkillSelectGood()
    },
    // 获取一级类
    getSkillSelectClassify () {
      this.$api.getSkillSelectClassify({
      }).then(res => {
        console.log(res)
        this.headerTabArray = res.data
      })
    },
    // 获取分类下的列表
    getSkillSelectGood () {
      this.$api.getSkillSelectGood({
        pageNum: this.pageActiveIndex,
        categoryId: this.classifyId,
        literatureName: this.searchText
      }).then(res => {
        console.log(res)
        this.classifyList = res.data
        this.pageTotals = Math.ceil(res.total / 10)
      })
    },
  //   // 优秀作品tab切换和接口请求
    headerTab (val, id) {
      if (this.id === id) {
        return
      }
      this.pageActiveIndex = 1
      this.id = id
      this.headerTabIndex = val
      this.classifyId = id
      this.getSkillSelectGood()
    },
  }
}
</script>

<style lang="less" scoped>
#excellentWorks{
  .excellentWorksContent{
    .pageNumber{
        width: 100%;
        height: 50px;
        padding: .2rem;
        text-align: center;
        .pageActive{
          color: #fff;
          background-color: #15A29C;
        }
        div{
          display: inline-block;
          font-size: .16rem;
          font-weight: 500;
          color: #333;
          line-height: .24rem;
          background-color: #fff;
          padding: .03rem .1rem;
          margin: 0 .05rem;
        }
      }
    width: 1200px;
    margin: auto;
    padding: .5rem 0;
    .excellentWorksContentHeader{
      background-color: #fff;
      padding: .2rem;
      border-bottom: 1px solid #eee;
      font-size: 0;
      .excellentWorksContentHeaderTab{
        display: inline-block;
        width: 70%;
        vertical-align: middle;
        border: 1px solid #fff;
        ul{
          li{
            position: relative;
            display: inline-block;
            height: .4rem;
            line-height: .4rem;
            margin-right: .1rem;
            p{
              font-size: 0.2rem;
              font-weight: 500;
              color: #333;
              line-height: .28rem;
            }
            .blue {
              color: #15a29c;
            }
            span{
              display: inline-block;
              width: 90%;
              height: .035rem;
              background-color: #15a29c;
              position: absolute;
              left: 50%;
              transform: translateX(-50%);
              bottom: 0;
            }
          }
        }
      }
      .excellentWorksContentHeaderSearch{
        display: inline-block;
        width: 30%;
        text-align: right;
        vertical-align: middle;
        label{
          border: 1px solid #DCDFE6;
          border-radius: .05rem;
          height: .4rem;
          line-height: .4rem;
          display: inline-block;
          box-sizing: content-box;
          margin-right: .1rem;
          position: relative;
          input#searchStylist{
            display: inline-block;
            color: #606266;
            font-size: .16rem;
            font-weight: 500;
            line-height: .4rem;
            width: 2rem;
            height: 100%;
            padding: 0 .2rem;
            border-radius: .05rem;
            padding-left: .4rem;
          }
          img{
            position: absolute;
            left: .08rem;
            top: 50%;
            transform: translateY(-50%);
            display: inline-block;
            width: .25rem;
            height: .25rem;
            background-color: #fff;
            z-index: 100;
          }
        }
        button{
          outline: none;
          border: 1px solid #ccc;
          border-radius: .05rem;
          line-height: .4rem;
          padding: 0 .2rem;
          background-color: #fff;
          color: #333;
          font-size: .16rem;
          display: inline-block;
        }
      }
    }
    .skillLiftPublicBookFlexRight {
    background-color: #fff;
    // width: calc(100% - 2.3rem);
    width: 100%;
    height: 4rem;
    padding-left: 0.2rem;
    ul {
      display: flex;
      justify-content: left;
      flex-wrap: wrap;
      li:nth-child(5n) {
        margin-right: 0;
      }
      li {
        display: inline-block;
        margin-bottom: 0.1rem;
        background-color: #fff;
        width: 2.2rem;
        margin-right: 0.1rem;
        img.publicBookFruitImg {
          width: 100%;
          height: 1.5rem;
          display: inline-block;
        }
        p {
          font-size: 0.14rem;
          font-weight: 500;
          color: #333;
          line-height: 0.26rem;
          height: 0.2rem;
          padding: 0 0.05rem;
        }
        div.publicBookRemark {
          padding: 0 0.05rem;
          img {
            width: 0.12rem;
            height: 0.12rem;
            display: inline-block;
          }
          span {
            font-size: 0.13rem;
            font-weight: 500;
            color: #aaa;
            line-height: 0.16rem;
          }
        }
      }
      li:nth-child(n + 5) {
        margin-bottom: 0;
      }
    }
  }
  }
}
</style>
